//
//  SomeSectorView.swift
//  FromWatchToCircle
//
//  Created by 张海峰 on 2018/6/1.
//  Copyright © 2018年 张海峰. All rights reserved.
//
/*写该demo的目的：主要是想从时钟开始，一步步窥见项目中和圆有关的东西，从而学习巩固，加深理解。
 (项目不定时更新，所以最好从下面地址获取最新demo),感觉我这个demo对你有启发或者帮助，欢迎fork 感谢star
 https://github.com/FighterLightning/FromWatchToCircle.git
 */
import UIKit
class SomeSectorView: UIView {
    var sectors: [CGFloat] = [0.15,0.3,0.5,0.05];
    //默认宽高
    var defaultWH: CGFloat = 100
    func initSomeSectorView(frame: CGRect) -> UIView {
        defaultWH = frame.size.width
        self.frame = frame
        self.backgroundColor = UIColor.lightGray
        return self
    }
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        let ctx: CGContext = UIGraphicsGetCurrentContext()!
        UIColor.red.set()// 颜色
        let centerXY: CGFloat = defaultWH/2 //中心点
        let WH: CGFloat  = defaultWH - ProgressViewItemMargin//直径
        let x: CGFloat  = ProgressViewItemMargin/2
        let y: CGFloat = ProgressViewItemMargin/2
        ctx.addEllipse(in: CGRect.init(x: x, y: y, width: WH, height: WH))
        ctx.fillPath()//实心的
        //ctx.strokePath()//空心的
         var angleStart1 :CGFloat = 0.0
        for i in 0 ..< sectors.count {
            let angleStart :CGFloat = angleStart1
            let angleEnd :CGFloat = 2 * .pi * sectors[i] + angleStart
            ctx.setFillColor(ZHFColor.zhf_randomColor().cgColor)
            ctx.move(to: CGPoint.init(x: centerXY, y: centerXY))
            ctx.addArc(center: CGPoint.init(x: centerXY, y: centerXY), radius: WH/2, startAngle: angleStart, endAngle: angleEnd, clockwise: false)//false 表示逆时针方向
            ctx.fillPath()
            angleStart1 = angleEnd
        }
    }
}
